package com.delu.controller;

import com.delu.data.Result;
import com.delu.em.ResultEnum;
import com.delu.entity.CarType;
import com.delu.mapper.CarTypesMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("carType")
@Api("汽车类型")
public class CarTypeController {
    @Resource
    private CarTypesMapper carTypesMapper;

    @GetMapping
    @ApiOperation("汽车类型查询")
    @ApiImplicitParam(name = "carType",value = "类型ID",required = true,paramType = "query")
    public Result selectCarType(@RequestParam("carType")Integer carType){
        System.out.println("汽车类型查询" + carType);
        List<CarType> carTypes = carTypesMapper.selectCarType(carType);
        return Result.response(ResultEnum.SUCCESS).setData(carTypes);
    }

    @PostMapping
    @ApiOperation("汽车类型的增加")
    @ApiImplicitParam(name = "CarType",value = "类型实体类",required = true,paramType = "body")
    public Result insertCarType(@RequestBody CarType carTypes){
        Integer i = carTypesMapper.insert(carTypes);
        System.out.println("汽车类型" + carTypes);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @PutMapping
    @ApiOperation("汽车类型的修改")
    @ApiImplicitParam(name = "CarType",value = "汽车类型实体类",required = true,paramType = "body")
    public Result updateCarType(@RequestBody CarType carTypes){
        Integer i = carTypesMapper.updateById(carTypes);
        System.out.println("汽车类型" + carTypes);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @DeleteMapping
    @ApiOperation("汽车类型的删除")
    @ApiImplicitParam(name = "carType",value = "汽车类型ID",required = true,paramType = "query")
    public Result deleteCarType(@RequestParam("carType")Integer carType){
        Integer i = carTypesMapper.deleteById(carType);
        System.out.println("汽车类型删除" + carType);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }
}
